<?php namespace Common\Model; 
//引入Model类
use Hdphp\Model\Model;
use Common\Model\TypeAttr;

//类型管理(实现增删改查)
class GoodsAttr extends Model{
	//绑定wsshop_goods_attr表
	protected $table = 'goods_attr';
	
	//处理内容页的商品属性等信息
	public function getTa($gid){
		$taid = $this->where("wsshop_goods_gid={$gid}")->lists('wsshop_type_attr_taid');
		$taid = array_unique($taid);
		
		$typeAttrModel = new TypeAttr();
		$typeAttrData = $typeAttrModel->whereIn('taid',$taid)->where("class ='规格'")->get();
		
		$taname = [];
		foreach ($typeAttrData as $k => $v) {
			$taname[]['taname'] = $v['taname'];
		}

		//获取商品属性信息
		$goodsAttrData = $this
						->join('type_attr','wsshop_type_attr_taid','=',C('database.prefix').'type_attr.taid')
//						->whereIn('taid',$taid)
						->orderBy('gavalue','ASC')
						->where("class ='规格'")
						->where("wsshop_goods_gid={$gid}")
						->get();

		foreach ($typeAttrData as $k => $v) {
			foreach ($goodsAttrData as $kk => $vv) {
				if($vv['taname'] ==$v['taname']){
					$typeAttrData[$k]['value'][] = $vv;
				}
			}
		}
		return $typeAttrData;
	}
}
